package com.flyco.modules.pms.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.flyco.common.api.vo.Result;
import com.flyco.common.system.query.QueryGenerator;
import com.flyco.common.aspect.annotation.AutoLog;
import com.flyco.common.util.oConvertUtils;
import com.flyco.modules.pms.entity.PmsProductMinimumQuantity;
import com.flyco.modules.pms.service.IPmsProductMinimumQuantityService;
import java.util.Date;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import com.flyco.common.system.base.controller.BaseController;
import com.flyco.poi.excel.ExcelImportUtil;
import com.flyco.poi.excel.def.NormalExcelConstants;
import com.flyco.poi.excel.entity.ExportParams;
import com.flyco.poi.excel.entity.ImportParams;
import com.flyco.poi.excel.view.EntityExcelView;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Description: 起订配置表
 * @Author: flyco
 * @Date:   2024-04-08
 * @Version: V1.0
 */
@Slf4j
@Api(tags="起订配置表")
@RestController
@RequestMapping("/f/pms/pmsProductMinimumQuantity")
public class PmsProductMinimumQuantityController extends BaseController<PmsProductMinimumQuantity, IPmsProductMinimumQuantityService> {
	@Autowired
	private IPmsProductMinimumQuantityService pmsProductMinimumQuantityService;
	
	/**
	 * 列表
	 */
	@AutoLog(value = "起订配置表")
	@ApiOperation(value="起订配置表", notes="起订配置表")
	@GetMapping(value = "/list")
	public Result<?> getByProductId(Long productId) {

		List<PmsProductMinimumQuantity> list = pmsProductMinimumQuantityService.getByProductId(productId);
		return Result.ok(list);
	}
	
	/**
	 * 新增
	 *
	 * @param pmsProductMinimumQuantity
	 * @return
	 */
	@AutoLog(value = "起订配置表-新增")
	@ApiOperation(value="起订配置表-新增", notes="起订配置表-新增")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody PmsProductMinimumQuantity pmsProductMinimumQuantity) {
		PmsProductMinimumQuantity info = pmsProductMinimumQuantityService.getByProductIdAndCompanyCode(pmsProductMinimumQuantity.getProductId(), pmsProductMinimumQuantity.getCompanyCode());
		if (info != null) {
			return Result.error("商品在该公司下已有配置，无法进行添加!");
		}
		pmsProductMinimumQuantityService.save(pmsProductMinimumQuantity);
		return Result.ok("添加成功");
	}
	
	/**
	 * 编辑
	 *
	 * @param pmsProductMinimumQuantity
	 * @return
	 */
	@AutoLog(value = "起订配置表-编辑")
	@ApiOperation(value="起订配置表-编辑", notes="起订配置表-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody PmsProductMinimumQuantity pmsProductMinimumQuantity) {
		pmsProductMinimumQuantityService.updateById(pmsProductMinimumQuantity);
		return Result.ok("编辑成功!");
	}

	 @AutoLog(value = "起订配置表-删除")
	 @ApiOperation(value="起订配置表-删除", notes="起订配置表-删除")
	 @DeleteMapping(value = "/delete")
	 public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		 pmsProductMinimumQuantityService.removeById(id);
		 return Result.ok("删除成功!");
	 }

}
